package com.lv.service.utils

import android.view.View
import com.lv.common.ktx.priceSmallDot
import com.lv.common.utils.MoneyUtil
import com.lv.common.utils.TimeUtil
import com.lv.service.bean.CategoryMoreBean

/**
 * 作者： ygx
 * 创建日期：2023/2/16 10:09 AM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 * <p>
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：
 */
object XmlUtils {
    @JvmStatic
    fun parseSplashTime(info: Int): String {
        return "跳过 $info "
    }

    @JvmStatic
    fun parsePrice(info: String?): String {
        if (info == null)
            return "0"
        val pinfo = MoneyUtil.moneydiv(info, "100")
        return "¥$pinfo"
    }

    @JvmStatic
    fun parsePrice1(info: String?): String {
        if (info == null)
            return "0"
        return MoneyUtil.moneydiv(info, "1")
    }

    @JvmStatic
    fun parsePrice1SmallDot(info: String?): String {
        if (info == null)
            return "0"
        return MoneyUtil.moneydiv(info, "1").priceSmallDot()
    }

    @JvmStatic
    fun parsePrice(info: Int?): String {
        if (info == null)
            return "0"
        val pinfo = MoneyUtil.moneydiv(info.toString(), "100")
        return "¥$pinfo"
    }

    @JvmStatic
    fun parsePrice_(info: String?): String {
        if (info == null || info.isEmpty())
            return "面议"
        var pinfo = ""
        if (info.contains("-")) {
            val split = info.split("-")
            pinfo = MoneyUtil.moneydiv(split[0], "100") + "-" + MoneyUtil.moneydiv(split[1], "100")
        } else {
            pinfo = MoneyUtil.moneydiv(info, "100")
        }
        return "¥$pinfo"
    }

    @JvmStatic
    fun parsePrice_(title: String, info: String?): String {
        if (info == null || info.isEmpty())
            return "面议"
        var pinfo = ""
        if (info.contains("-")) {
            val split = info.split("-")
            pinfo = MoneyUtil.moneydiv(split[0], "100") + "-" + MoneyUtil.moneydiv(split[1], "100")
        } else {
            pinfo = MoneyUtil.moneydiv(info, "100")
        }
        return "$title$pinfo"
    }

    @JvmStatic
    fun parsePrice_(title: String, info: String?, info2: String?): String {
        if (info == null || info.isEmpty())
            return "面议"
        var pinfo = ""
        if (info2.isNullOrEmpty() && info != info2) {
            pinfo = MoneyUtil.moneydiv(info, "100") + "-" + MoneyUtil.moneydiv(info2, "100")
        } else {
            pinfo = MoneyUtil.moneydiv(info, "100")
        }
        return "$title$pinfo"
    }

    @JvmStatic
    fun parsePrice2(info: Int): String {
        val pinfo = MoneyUtil.moneydiv(info.toString(), "100")
        return "价格：${pinfo}元"
    }

    @JvmStatic
    fun parseTimeByFormat(info: Long, format: String): String {
        return TimeUtil.longNeedTimeByFormat(info, format)
    }

    @JvmStatic
    fun parseTime2(hint: String? = "", info: Long): String {
        var status = ""
        status = TimeUtil.longNeedTimes2(info)
        if (hint.isNullOrEmpty()) {
            return status
        }
        status = "$hint：$status"
        return status
    }

    @JvmStatic
    fun parseTime3(hint: String? = "", info: Long): String {
        var status = ""
        status = TimeUtil.longNeedTimes(info)
        if (hint.isNullOrEmpty()) {
            return status
        }
        status = "$hint：$status"
        return status
    }

    @JvmStatic
    fun parseTime_(hint: String? = "", info: Long): String {
        var status = ""
        status = TimeUtil.longNeedTime_(info)
        if (hint.isNullOrEmpty()) {
            return status
        }
        status = "$hint：$status"
        return status
    }

    @JvmStatic
    fun parseTimeMD(hint: String? = "", info: Long): String {
        var status = ""
        status = TimeUtil.longNeedTimeMD2(info)
        if (hint.isNullOrEmpty()) {
            return status
        }
        status = "$hint：$status"
        return status
    }

    /**
     * 电话号码中间加 *
     */
    @JvmStatic
    fun parsePhone(phoneNum: String?): String {
        if (phoneNum.isNullOrEmpty() || phoneNum.length < 11) {
            return ""
        }
        val substart = phoneNum.substring(0, 3)
        val subend = phoneNum.substring(phoneNum.length - 4, phoneNum.length)
        return "$substart****$subend"
    }

    @JvmStatic
    fun parseInt2String(info: Int?): String {
        if (info == null)
            return "0"
        return info.toString()
    }

    @JvmStatic
    fun parseString(info: String?, info2: String?): String {
        if (info == null || info.isEmpty())
            return info2 ?: ""
        return info
    }

    @JvmStatic
    fun parseBoole(info: String?, info2: String?): Boolean {
        if (info.isNullOrEmpty() || info2.isNullOrEmpty())
            return false
        return info == info2
    }

    @JvmStatic
    fun parseBooleStringCount(info: String?, info2: String?): Boolean {
        var info_ = info
        if (info.isNullOrEmpty()) {
            info_ = "0"
        }
        var info2_ = info2
        if (info2.isNullOrEmpty()) {
            info2_ = "0"
        }

        return info_ == info2_
    }

    @JvmStatic
    fun parseBoole(info: Int = 0, info2: Int = 0): Boolean {

        return info > info2
    }

    /**
     * 商品是否可以上传或编辑
     */
    @JvmStatic
    fun parseBooleGoodsBuyEnable(
        mSelectMediaSize: Int,
        name: String?,
        cpName: String?,
        addressShow: Boolean,
        category: Boolean
    ): Boolean {
        if (mSelectMediaSize == 0) {
            return false
        }
        if (name.isNullOrEmpty()) {
            return false
        }
        if (cpName.isNullOrEmpty()) {
            return false
        }
        if (!addressShow) {
            return false
        }
//        if (!paramsSet) {
//            return false
//        }
        if (!category) {
            return false
        }

        return true
    }

    @JvmStatic
    fun parseMessageTitle(info: String?): String {
        if (info.isNullOrEmpty())
            return ""
        when (info) {
            "100" -> return "完善信息"
            "101" -> return "新功能上线"
            "102" -> return "书刊上新"
            "103" -> return "商品风险下架"
            "104" -> return "货圈风险下架"
            "105" -> return "货圈上线通过"
            "106" -> return "货圈上线拒绝"
            "107" -> return "商品上架通过"
            "108" -> return "商品上架拒绝"
            "109" -> return "营销活动通知"
            "110" -> return "访问消息"
            "111" -> return "点赞货圈"
            "112" -> return " 关注店铺"
            "113" -> return " 收藏商品"
            "114" -> return " 拨打电话"
            else -> {
                return "未知消息"
            }
        }
    }

    /**
     * @param fontColor 0 黑 1 红 2 金
     * @param code 0 年卡 1 期卡
     */
    @JvmStatic
    fun parseCardsName(fontColor: String?, code: String?): String {
        var cardName = ""
        when (fontColor) {
            "0" -> cardName = "黑色名片"
            "1" -> cardName = "红色名片"
            "2" -> cardName = "金色名片"
        }
        when (code) {
            "0" -> cardName = "${cardName}年卡"
            "1" -> cardName = "${cardName}期卡"
        }
        return cardName
    }

    @JvmStatic
    fun parseVis(isvis: Boolean): Int {
        return if (isvis) View.VISIBLE else View.GONE
    }

    @JvmStatic
    fun parseVis(info: Int, isvis: Boolean): Int {
        var tag = View.VISIBLE
        if (isvis) {
            if (info > 0) {
                tag = View.VISIBLE
            } else {
                tag = View.GONE
            }
        } else {
            tag = View.GONE
        }
        return tag
    }

    @JvmStatic
    fun parseVis(info: Int?): Int {
        var infos = 0
        if (info == null) {
            infos = 0
        } else {
            infos = info
        }
        var tag = View.VISIBLE
        if (infos <= 0) {
            tag = View.VISIBLE
        } else {
            tag = View.GONE
        }

        return tag
    }

    @JvmStatic
    fun parseCategory(info: CategoryMoreBean): String {
        var tag = ""
        val category = info.category
        category?.let {
            category.forEach { item ->
                tag = "$tag | ${item.name}"
//                if (item.name.contains("-")) {
//                    val subtag = item.name.split("-")[1]
//                    tag = "$tag  |  ${subtag}"
//                }
            }
        }
        if (tag.startsWith(" | ")) {
            tag = tag.trim()
            tag = tag.drop(1)
            tag = tag.trim()
        }
        return tag
    }

}